import { Controller, Get, Post, Body, HttpCode, Req, Query } from "@nestjs/common";
import { UserService } from "./user.service";
// import { CreateUserDto } from "./dto/create-user.dto";
// import { UpdateUserDto } from "./dto/update-user.dto";
import { LoginUserDto } from "./dto/login-user.dto";
import { ChangePasswordUserDto } from "./dto/changePassword-user.dto";
import { ListUserDto } from "./dto/list-user.dto";
import { Public } from "../common/decorator/auth.decorator";
import { Request } from "express";
@Controller("user")
export class UserController {
  constructor(private readonly userService: UserService) {}

  // @Post()
  // create(@Body() createUserDto: CreateUserDto) {
  //   return this.userService.create(createUserDto);
  // }

  @Post("/login")
  @HttpCode(200)
  @Public()
  login(@Body() loginUserDto: LoginUserDto) {
    return this.userService.login(loginUserDto);
  }

  @Get("/info")
  findOne(@Req() request: Request) {
    const { username } = request["user"];
    return this.userService.findOne(username);
  }

  @Post("/changePassword")
  @HttpCode(200)
  changePassword(@Body() body: ChangePasswordUserDto, @Req() request: Request) {
    const { username } = request["user"];
    return this.userService.changePassword(username, body);
  }

  @Get("/list")
  findList(@Query() query: ListUserDto) {
    return this.userService.findList(query);
  }
  // @Get()
  // findAll() {
  //   return this.userService.findAll();
  // }

  // @Patch(":id")
  // update(@Param("id") id: string, @Body() updateUserDto: UpdateUserDto) {
  //   return this.userService.update(+id, updateUserDto);
  // }

  // @Delete(":id")
  // remove(@Param("id") id: string) {
  //   return this.userService.remove(+id);
  // }
}
